package cn.upbos.demo;

import com.alibaba.fastjson.JSON;
import com.upbos.core.ret.RetData;
import com.upbos.sso.SsoManager;
import com.upbos.sso.UserContext;
import com.upbos.sso.entity.SsoUser;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("demo")
public class DemoController {

    @Resource
    private SsoManager ssoManager;

    @RequestMapping("listUser")
    public RetData listUser(String name) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("name", name);
        map.put("sex", "男");
        map.put("addr", "北京市朝阳区");
        return RetData.success(map);
    }

    @RequestMapping("getUser")
    public RetData getUser(UserContext context) {
        SsoUser ssoUser = context.getSsoUser();
        if (ssoUser == null) {
            return RetData.fail("用户会话过期");
        }
        return RetData.success(ssoUser);
    }
}
